/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MessageHandler;

import Core.MessageBuilder;
import Slave.SlaveInfo;
import org.openymsg.network.Session;

/**
 *
 * @author Mr Bao
 */
public class SlaveReportMessageHandler implements IMessageHandler {

    public Object Process(String message, Session session) {
        System.out.println("Message: " + message);
        int index = message.indexOf(MessageBuilder.ONE);
        String tmp = message.substring(index + 1);
        String[] content = tmp.split(MessageBuilder.TWO.trim());
        for (String str : content) {
            System.out.println(" : " + str);
        }
        int id = Integer.parseInt(content[0].trim());
        String address = content[1];
        int port = Integer.parseInt(content[2]);
        long numberConnections = Integer.parseInt(content[3]);
        SlaveInfo slaveInfo = new SlaveInfo(id, address, port);
        slaveInfo.setCurrentConnections(numberConnections);
        return slaveInfo;
    }
}
